/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * main.c
 * Copyright (C) The Pennsylvania State University 2008 <tpk5010@psu.edu>
 * 
 * main.c is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* main.c is the main application source file. Here we define our main function,
   and helper create and destroy functions for memory management. We also define
   a few locale stuffs. The main application loop is inside here, and we connect
   UI signals to their corresponding callback functions in callbacks.c/h
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <hildon-1/hildon/hildon-program.h>
#include <libintl.h>
#include <locale.h>
#include <libosso.h>
#define _(String) gettext(String)
#include <config.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "ui/callbacks.h"
#include "appdata.h"
#include "ui/interface.h"

/*
 * Standard gettext macros.
 */
#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define N_(String) (String)
#  endif
#else
#  define textdomain(String) (String)
#  define gettext(String) (String)
#  define dgettext(Domain,Message) (Message)
#  define dcgettext(Domain,Message,Type) (Message)
#  define bindtextdomain(Domain,Directory) (Domain)
#  define _(String) (String)
#  define N_(String) (String)
#endif

/* For testing propose use the local (not installed) glade file */
/* #define GLADE_FILE PACKAGE_DATA_DIR"/nc2ifeel_nokia_client/glade/nc2ifeel_nokia_client.glade" */
#define GLADE_FILE "ui/nc2ifeel_nokia_client.glade"

static AppData *create_data () {

    AppData *result = g_new0 (AppData, 1);

    result->osso = osso_initialize (PACKAGE, VERSION, TRUE, NULL);
    g_assert (result->osso);
    return result;
}

static void destroy_data (AppData *data) {

    g_free (data);
}


int main(int argc, char *argv[]) {

 	AppData* data;
	HildonProgram* program;
	AppUIData* main_view;

/* Initalize the locale data */
#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif
	
	gtk_set_locale ();
	gtk_init (&argc, &argv);
	program = HILDON_PROGRAM (hildon_program_get_instance ());
	g_set_application_name( _("NC2IF Client"));

	if(!g_thread_supported ()) {
		g_thread_init (NULL);
	}

	data = create_data ();
	data->program = program;
	main_view = interface_main_view_new (data);

	hildon_program_add_window (data->program, data->window);

	/* This would be a good place to put signal connections. */

	gtk_widget_show (GTK_WIDGET (program));
	gtk_main ();

	interface_main_view_destroy (main_view);
	destroy_data (data);

	exit(0);
}
